package com.jcl.recruit.resume.provider;

import com.jcl.recruit.mapper.provider.SqlProvider;
import com.jcl.recruit.resume.model.ResumeBasicInfo;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

public class ResumeBasicInfoSqlProvider implements SqlProvider<ResumeBasicInfo> {

    private static final String TABLE_NAME = "resume_basic_info";

    public String insert(ResumeBasicInfo entity) {
        BEGIN();
        INSERT_INTO(TABLE_NAME);

        if (entity.getApplyStatus() != null) {
            VALUES("apply_status", "#{applyStatus,jdbcType=INTEGER}");
        }

        if (entity.getApplyDepartment() != null) {
            VALUES("apply_department", "#{applyDepartment,jdbcType=VARCHAR}");
        }

        if (entity.getApplyPosition() != null) {
            VALUES("apply_position", "#{applyPosition,jdbcType=VARCHAR}");
        }

        if (entity.getApplyDate() != null) {
            VALUES("apply_date", "#{applyDate,jdbcType=DATE}");
        }

        if (entity.getUpdateDate() != null) {
            VALUES("update_date", "#{updateDate,jdbcType=DATE}");
        }

        if (entity.getTags() != null) {
            VALUES("tags", "#{tags,jdbcType=VARCHAR}");
        }

        if (entity.getSource() != null) {
            VALUES("source", "#{source,jdbcType=INTEGER}");
        }

        if (entity.getSourceSub() != null) {
            VALUES("source_sub", "#{sourceSub,jdbcType=VARCHAR}");
        }

        if (entity.getApplyOtherJid() != null) {
            VALUES("apply_other_jid", "#{applyOtherJid,jdbcType=VARCHAR}");
        }

        if (entity.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }

        if (entity.getCorpCode() != null) {
            VALUES("corp_code", "#{corpCode,jdbcType=VARCHAR}");
        }

        if (entity.getChannelAccount() != null) {
            VALUES("channel_account", "#{channelAccount,jdbcType=VARCHAR}");
        }

        if (entity.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }

    public String updateByPrimaryKey(ResumeBasicInfo entity) {

        BEGIN();
        UPDATE(TABLE_NAME);

        if (entity.getSource() != null) {
            SET("source = #{source,jdbcType=INTEGER}");
        }

        if (entity.getSourceSub() != null) {
            SET("source_sub = #{sourceSub,jdbcType=VARCHAR}");
        }

        if (entity.getApplyStatus() != null) {
            SET("apply_status = #{applyStatus,jdbcType=INTEGER}");
        }

        if (entity.getApplyDepartment() != null) {
            SET("apply_department = #{applyDepartment,jdbcType=VARCHAR}");
        }

        if (entity.getApplyPosition() != null) {
            SET("apply_position = #{applyPosition,jdbcType=VARCHAR}");
        }

        if (entity.getApplyDate() != null) {
            SET("apply_date = #{applyDate,jdbcType=DATE}");
        }

        if (entity.getUpdateDate() != null) {
            SET("update_date = #{updateDate,jdbcType=DATE}");
        }

        if (entity.getApplyOtherJid() != null) {
            SET("apply_other_jid = #{applyOtherJid,jdbcType=VARCHAR}");
        }

        if (entity.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }

        if (entity.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (entity.getTags() != null) {
            SET("tags = #{tags,jdbcType=VARCHAR}");
        }

        if (entity.getChannelAccount() != null) {
            SET("channel_account = #{channelAccount,jdbcType=VARCHAR}");
        }

        WHERE("id = #{id,jdbcType=INTEGER}");

        return SQL();
    }

}